
//添加事件
function getEvent() {
    document.getElementById('searchBtn').addEventListener("click", function () {
        searchData()
    });
    document.getElementById('dutyRoster').addEventListener("click", function () {
        let className = document.getElementById('dutyRosterLabel').className;
        if (className.includes('labelOpen')) {
            document.getElementById('dutyRosterLabel').className = 'label'
        } else {
            document.getElementById('dutyRosterLabel').className = 'label labelOpen'
        }
    });
    document.getElementById('dutyRosterLabel').addEventListener("click", function () {
        window.location.href = `./navigationList.html?duty=${true}`;
    });
}
function searchData() {
    let value = document.getElementById('myInput').value;
    //console.log(value)
    window.location.href = `./navigationList.html?searchStr=${value}`;
}
function splitIntoChunks(array, chunkSize) {
    let chunks = [];
    for (let i = 0; i < array.length; i += chunkSize) {
        let chunk = array.slice(i, i + chunkSize);
        chunks.push(chunk);
    }
    //console.log(chunks)
    return chunks;
}
function queryMajorReprints() {
    ajax('GET', `portalWebsite/homepage/queryMajorReprints`, null, function (res) {
        let data = res.data || [];
        let list = data || [];
        if (list.length) {
            let TOPPING = list.filter(item => {
                return item.majorReprints == 'TOPPING'
            })
            let SECONDCOLUMN = list.filter(item => {
                return item.majorReprints !== 'TOPPING'
            })
            let majorReprints = TOPPING.concat(SECONDCOLUMN);
            let domList = document.querySelectorAll('.notificationItem');
            Array.from(domList).forEach((e, index) => {
                let title = majorReprints[index] && majorReprints[index].title ? majorReprints[index].title : ''
                e.innerText = title || ''
                e.addEventListener("click", function () {
                    jumpArticle(majorReprints[index])
                });
            })
        } else {
            document.getElementById('notification').style.display = 'none'
        }
    })
}
function queryNotice() {
    ajax('GET', `portalWebsite/homepage/queryNotice`, null, function (res) {
        let data = res.data || [];
        let list = data || [];
        let noticeList = ''
        list.forEach(element => {
            noticeList += element.content
        });
        if (noticeList) {
            document.getElementById('noticeText').innerText = noticeList
            document.getElementById('notice').style.opacity = 1
        } else {
            document.getElementById('notice').style.opacity = 0
        }
    })
}
//表彰
function queryCommendation() {
    ajax('GET', `portalWebsite/homepage/queryCommendation`, null, function (res) {
        let data = res.data || [];
        let mySwiper = document.getElementById('swiper-wrapper-6');
        let htmlStr = ''
        //console.log(data)
        data.forEach((e, index) => {
            console.log(e)
            let domStr = `<div class='swiper-slide jumpArticle' data-id='${e.jumpType == "ARTICLE" ? e.articleId : ''}'
            data-url='${e.jumpType == "URL" ? e.url : ''}'>
                        <div class='imgBox'><img src=${$baseUrl.fileServiceUrl}portalWebsite/files/download?fileId=${e.filesId} /></div>
                                <div class="roll-box"><div class="text" title="${e.title}">${e.title}</div></div>
                        </div>`
            htmlStr += domStr
        })
        mySwiper.innerHTML = htmlStr
        mySwiper_init_6();
        addClickEvent();
    })
}
// 查询政务公开
function queryGovernmentTransparencyPageList() {
    ajax('GET', `portalWebsite/homepage/queryGovernmentTransparencyPageList?page=${1}&size=${100}`, null, function (res) {
        let data = res.data || {};
        //console.log(data, 'datadatadata')
        let mySwiper = document.getElementById('swiper-wrapper-4');
        let htmlStr = ''
        let sweiperList = splitIntoChunks(data.list || [], 5)
        //console.log(sweiperList)
        sweiperList.forEach((e, index) => {
            let childrenDomStr = ''
            e.forEach((item, i) => {
                childrenDomStr += `<div class='swiperFlex'>
                        <img src=${$baseUrl.fileServiceUrl}portalWebsite/files/download?fileId=${item.filesId} />
                        <div class='jumpArticle' title="${item.name}" data-url='${item.url}'>${item.name}</div>
                        </div>`
            })
            htmlStr += "<div class='swiper-slide'>" + childrenDomStr + "</div>"
            //console.log(childrenDomStr)
        })
        mySwiper.innerHTML = htmlStr
        //console.log(htmlStr, 'datadatadata')
        mySwiper_init_4();
        addClickEvent()
    })
}
// 查询常用系统
function queryPageList() {
    ajax('GET', `portalWebsite/homepage/queryPageList?page=${1}&size=${100}`, null, function (res) {
        let data = res.data || {};
        //console.log(data, 'datadatadata')
        let mySwiper = document.getElementById('swiper-wrapper-5');
        let htmlStr = ''
        let sweiperList = splitIntoChunks(data.list || [], 6)
        //console.log(sweiperList)
        sweiperList.forEach((e, index) => {
            let childrenDomStr = ''
            e.forEach((item, i) => {
                childrenDomStr += `<div  class='swiperFlex'>
                        <div class='jumpArticle' title="${item.systemName}"  data-url='${item.url}'>${item.systemName}</div>
                        </div>`
            })
            htmlStr += "<div class='swiper-slide'>" + childrenDomStr + "</div>"
            //console.log(childrenDomStr)
        })
        mySwiper.innerHTML = htmlStr
        mySwiper_init_5();
        addClickEvent()
    })
}
function queryDuty() {
    ajax('GET', 'portalWebsite/homepage/queryToday', null, function (res) {
        var { data } = res
        data = data || {}
        document.getElementById('dutyDate').innerText = data.dutyDate || '--'
        document.getElementById('leader').innerText = data.leader || '--'
        document.getElementById('officer').innerText = data.officer || '--'
        document.getElementById('driver').innerText = data.driver || '--'
    })
}
function mySwiper_init_6() {
    new Swiper(".mySwiper_6", {
        autoplay: {
            delay: 3000,
            disableOnInteraction: false,
        },
        pagination: {
            el: ".swiper-pagination",
            clickable: true,
        },
    })
}
function mySwiper_init_5() {
    new Swiper(".mySwiper_5", {
        autoplay: {
            delay: 3000,
            disableOnInteraction: false,
        },
        pagination: {
            el: ".swiper-pagination",
            clickable: true,
        },
    })
}
function mySwiper_init_4() {
    new Swiper(".mySwiper_4", {
        autoplay: {
            delay: 3000,
            disableOnInteraction: false,
        },
        pagination: {
            el: ".swiper-pagination",
            clickable: true,
        },
    })
}
function mySwiper_init_3() {
    new Swiper(".mySwiper_3", {
        slidesPerView: 3,
        spaceBetween: 30,
        autoplay: {
            delay: 3000,
            disableOnInteraction: false,
        },
        pagination: {
            el: ".swiper-pagination",
            clickable: true,
        },
    })
}
function mySwiper_init_2() {
    new Swiper(".mySwiper_2", {
        slidesPerView: 3,
        spaceBetween: 30,
        autoplay: {
            delay: 3000,
            disableOnInteraction: false,
        },
        pagination: {
            el: ".swiper-pagination",
            clickable: true,
        },
    })
}
function mySwiper_init_1() {
    new Swiper(".mySwiper_1", {
        autoplay: {
            delay: 3000,
            disableOnInteraction: false,
        },
        pagination: {
            el: ".swiper-pagination",
            clickable: true,
            renderBullet: function (index, className) {
                return '<div class="' + className + '"></div>';
            },
        },
    }).on('slideChange', function (e) {
        // 获取当前活动的下标（索引） 
        let { activeIndex } = e;
        getSwiperTitle(activeIndex);
    });
}
function getSwiperTitle(index) {
    document.getElementById('mySwiper_title_1').innerText = mySwiperList_1[index].title
}
function queryBayWindow() {
    let emailList_left = document.getElementById('emailList_left');
    let emailList_right = document.getElementById('emailList_right');
    emailList_left.style.display = 'none';
    emailList_right.style.display = 'none';
    ajax('GET', 'portalWebsite/homepage/queryBayWindow', null, function (res) {
        let list = res.data || []
        list = list.map(item => {
            return {
                ...item,
                isClose: false,
                imgUrl: `${$baseUrl.fileServiceUrl}portalWebsite/files/download?fileId=${item.filesId}`
            }
        })
        let listLeft = list.filter(item => { return item.displayLocation == 'LEFT' });
        let listRight = list.filter(item => { return item.displayLocation == 'RIGHT' });
        // console.log(listLeft, listRight)
        let htmlStrLeft = ''
        let htmlStrRight = ''
        listLeft.forEach((e, i) => {
            if (e.filesId) {
                htmlStrLeft += `<div class='jumpArticle' data-url='${e.url}'>
                <img src='${e.imgUrl}'/>
                </div>`
            }
        })
        listRight.forEach((e, i) => {
            if (e.filesId) {
                htmlStrRight += `<div class='jumpArticle' data-url='${e.url}'>
                <img src='${e.imgUrl}'/>
                </div>`
            }
        })
        if (listLeft.length) {
            emailList_left.style.display = 'block';
            emailList_left.innerHTML = "<div class='btn closeBtn' id='closeBtnLeft'><div class='close'><img src='../assets/close.png'/></div><div>关闭</div></div><div class='list'>" + htmlStrLeft + "</div><div class='openBtn' id='openBtnLeft'></div>"
        }
        if (listRight.length) {
            emailList_right.style.display = 'block';
            emailList_right.innerHTML = "<div class='btn closeBtn' id='closeBtnRight'><div>关闭</div><div class='close'><img src='../assets/close.png'/></div></div><div class='list'>" + htmlStrRight + "</div><div class='openBtn' id='openBtnRight'></div>"
        }
        setWindowEvent();
    })
}
//添加弹窗事件
function setWindowEvent() {
    let closeBtnLeft = document.getElementById('closeBtnLeft')
    let closeBtnRight = document.getElementById('closeBtnRight')

    let openBtnLeft = document.getElementById('openBtnLeft');
    let openBtnRight = document.getElementById('openBtnRight');

    let emailList_left = document.getElementById('emailList_left')
    let emailList_right = document.getElementById('emailList_right')
    if (Number(sessionStorage.closeBtnLeft || 0)) {
        emailList_left.className = emailList_left.className + ' closeLeft'
    }
    if (Number(sessionStorage.closeBtnRight || 0)) {
        emailList_right.className = emailList_right.className + ' closeRight'
    }
    isShowBtn();
    //关闭左侧窗口
    closeBtnLeft && closeBtnLeft.addEventListener("click", function () {
        if (Number(sessionStorage.closeBtnLeft || 0)) {
            emailList_left.className = emailList_left.className.replace('closeLeft', '')
            sessionStorage.setItem('closeBtnLeft', 0)
        } else {
            emailList_left.className = emailList_left.className + ' closeLeft'
            sessionStorage.setItem('closeBtnLeft', 1)
        }
        isShowBtn();
    });
    //关闭右侧窗口
    closeBtnRight && closeBtnRight.addEventListener("click", function () {
        if (Number(sessionStorage.closeBtnRight || 0)) {
            emailList_right.className = emailList_right.className.replace('closeRight', '');
            sessionStorage.setItem('closeBtnRight', 0);
        } else {
            emailList_right.className = emailList_right.className + ' closeRight'
            sessionStorage.setItem('closeBtnRight', 1)
        }
        isShowBtn();
    });
    //打开左侧窗口
    openBtnLeft && openBtnLeft.addEventListener("click", function () {
        if (Number(sessionStorage.closeBtnLeft || 0)) {
            emailList_left.className = emailList_left.className.replace('closeLeft', '')
            sessionStorage.setItem('closeBtnLeft', 0)
        } else {
            emailList_left.className = emailList_left.className + ' closeLeft'
            sessionStorage.setItem('closeBtnLeft', 1)
        }
        isShowBtn();
    });
    //打开右侧窗口
    openBtnRight && openBtnRight.addEventListener("click", function () {
        if (Number(sessionStorage.closeBtnRight || 0)) {
            emailList_right.className = emailList_right.className.replace('closeRight', '')
            sessionStorage.setItem('closeBtnRight', 0)
        } else {
            emailList_right.className = emailList_right.className + ' closeRight'
            sessionStorage.setItem('closeBtnRight', 1)
        }
        isShowBtn();
    });
}
function isShowBtn() {
    let openBtnLeft = document.getElementById('openBtnLeft');
    let openBtnRight = document.getElementById('openBtnRight');
    if (openBtnLeft) {
        if (Number(sessionStorage.closeBtnLeft || 0)) {
            openBtnLeft.style.display = 'block'
        } else {
            openBtnLeft.style.display = 'none'
        }
    }
    if (openBtnRight) {
        if (Number(sessionStorage.closeBtnRight || 0)) {
            openBtnRight.style.display = 'block'
        } else {
            openBtnRight.style.display = 'none'
        }
    }
}


//后去页面基本数据（背景图自定义按钮颜色）
function queryEndPage() {
    document.getElementById('nav').style.backgroundColor = sessionStorage.navigationColor || '#164fa6';
    document.getElementById('footer').style.backgroundColor = sessionStorage.navigationColor || '#164fa6';
    document.getElementById('active').style.backgroundColor = sessionStorage.hoverColor || '#137bff';
    ajax('GET', 'portalWebsite/homepage/queryEndPage', null, function (res) {
        endData = res.data || {}
        var backgroundImageUrl = `${$baseUrl.fileServiceUrl}portalWebsite/files/download?fileId=${endData.backgroundImage}`
        var headerImageUrl = `${$baseUrl.fileServiceUrl}portalWebsite/files/download?fileId=${endData.headerImage}`
        var columnChartUrl = `${$baseUrl.fileServiceUrl}portalWebsite/files/download?fileId=${endData.columnChart}`
        var navigationColor = endData.navigationColor || '#164fa6'
        var hoverColor = endData.hoverColor || '#137bff'
        document.getElementById('ZWGK').innerHTML = endData.rightColumnOne || '政务公开';
        document.getElementById('CYXT').innerHTML = endData.rightColumnTwo || '常用系统';
        endData.backgroundImage && (document.getElementById('homePage').style.backgroundImage = `url(${backgroundImageUrl})`);
        endData.headerImage && (document.getElementById('homePageLogo').src = headerImageUrl);
        document.getElementById('nav').style.backgroundColor = navigationColor;
        document.getElementById('footer').style.backgroundColor = navigationColor;
        document.getElementById('active').style.backgroundColor = hoverColor;
        document.getElementById('headerName').innerHTML = endData.headerName || '';
        document.getElementById('organizer').innerHTML = endData.organizer || '';
        document.getElementById('phoneNumber').innerHTML = endData.phoneNumber || '';
        document.getElementById('address').innerHTML = endData.address || '';
        document.getElementsByTagName("title")[0].textContent = endData.headerName || '公安官网';
        document.getElementById('dutyOne').innerHTML = `${endData.dutyOne || '值班领导'}:`;
        document.getElementById('dutyTwo').innerHTML = `${endData.dutyTwo || '值班人员'}:`;
        document.getElementById('dutyThree').innerHTML = `${endData.dutyThree || '值班驾驶员'}:`;
        sessionStorage.setItem('hoverColor', hoverColor);
        sessionStorage.setItem('navigationColor', navigationColor);

        if (endData.topArticle) {
            document.getElementById('notificationLabel').innerHTML = endData.topArticle;
        } else {
            document.getElementById('notificationLabel').style.display = 'none'
        }
        if (endData.columnChart) {
            document.getElementById('bannerBg').style.backgroundImage = `url(${columnChartUrl})`;
        } else {
            document.getElementById('bannerBg').style.display = 'none'
        }
    })
}
//初始化下拉组件
function initSelect(id, list) {
    var select = document.getElementById(id);
    list.forEach((e, index) => {
        var newDiv = document.createElement('option');
        newDiv.value = e.portalWebsiteId;
        newDiv.className = 'option';
        newDiv.innerHTML = e.name
        select.appendChild(newDiv);
    })
}
//获取nav
function queryHomepageNavigation() {
    ajax('GET', 'portalWebsite/homepage/queryHomepageNavigation', null, function (res) {
        var data = res.data || []
        var tagList = document.getElementById('tagList');
        var children = Array.from(tagList.children)
        var tagList_start = children[0];
        var tagList_end = children[children.length - 1];
        tagList.appendChild(tagList_start)
        data.forEach(e => {
            var newDiv = document.createElement('div');
            newDiv.textContent = e.navigationName;
            newDiv.className = 'tag newTag'
            tagList.appendChild(newDiv);
        });
        tagList.appendChild(tagList_end)
        var newTagList = document.querySelectorAll('.newTag');
        Array.from(newTagList).forEach((e, index) => {
            e.addEventListener("click", function () {
                if (data[index].functionType == 'URL') {
                    data[index].url && window.open(data[index].url, '_blank')
                } else {
                    window.location.href = `./navigationList.html?navigationId=${data[index].navigationId}`;
                }
            });
        })
        setNavHoverColor(newTagList)
    })
}
function queryNavigation() {
    ajax('GET', 'portalWebsite/homepage/queryNavigation', null, function (res) {
        var data = res.data || []
        //console.log(data)
        var navigationObj = {}
        data.forEach(e => {
            if (!navigationObj[e.level]) {
                navigationObj[e.level] = []
            }
            navigationObj[e.level].push(e)
        })
        var list = [];
        for (let key in navigationObj) {
            list.push(navigationObj[key])
        }
        let noticeList = document.getElementById('noticeList');
        let noticeHtmlStr = ''
        list.forEach((e, i) => {
            if (i > 0) {
                noticeHtmlStr += `<div class="noticeItem"><div class="tags">
                                <div class="btnList" id="noticeBtnList_${i + 1}"></div>
                                <div class="moreBtn">更多</div>
                            </div>
                            <div class="list btn">
                                <div id="noticeUl_${i + 1}"></div>
                            </div>
                        </div>`
            }
            noticeList.innerHTML = noticeHtmlStr
        })
        list.forEach((e, i) => {
            let noticeBtnList = document.getElementById(`noticeBtnList_${i + 1}`);
            e.forEach((e, index) => {
                var newDiv = document.createElement('div');
                newDiv.className = `btn btn${i}`;
                newDiv.innerHTML = e.navigationName
                newDiv.onclick = function () {
                    getNavigationInfo(e, `btn${i}`, index, i)
                };
                noticeBtnList.appendChild(newDiv);
            })
            if (e[0]) {
                getNavigationInfo(e[0], `btn${i}`, 0, i)
            }
        })
        let moreBtnList = document.querySelectorAll('.moreBtn')
        Array.from(moreBtnList).forEach(e => {
            e.addEventListener("click", function () {
                window.location.href = `./navigationList.html?navigationId=${data[0].navigationId}`;
            });
        })
    })
}
function getNavigationInfo(params, className, index, domIndex) {
    let btnList = document.querySelectorAll(`.${className}`)
    Array.from(btnList).forEach(e => {
        e.className = `btn ${className}`
    })
    // console.log('***', index)
    if (domIndex) {
        btnList[index].className = `btn ${className} btn-active-other`
    } else {
        btnList[index].className = `btn ${className} btn-active`
    }
    queryByNavigationId(params.navigationId, domIndex)
}
function queryByNavigationId(id, domIndex) {
    ajax('GET', `portalWebsite/homepage/queryByNavigationId?navigationId=${id}`, null, function (res) {
        let data = res.data || [];
        //console.log(data)
        //console.log(`noticeUl_${domIndex + 1}`)
        let noticeUl = document.getElementById(`noticeUl_${domIndex + 1}`);
        let htmlStr = ''
        data.forEach((e, index) => {
            if (index < 6) {
                let domStr = '';
                let className = ''
                if (isToday(e.publishTime)) {
                    className = 'newData'
                } else {
                    className = 'noNewData'
                }
                // console.log(isToday(e.publishTime))
                domStr = `<div class='noticeInfo jumpArticle' title="${e.title}"  data-id='${e.articleId}'>
                <div class="noticeTitle">${e.title}</div>
                <div class="noticeTime"><span>${e.publishTime}</span><div class="${className}"><span>new</span></div></div>
                </div>`
                htmlStr += domStr
            }
        })
        noticeUl.innerHTML = htmlStr
        addClickEvent()
    })
}
function isToday(dateString) {
    const today = new Date();
    const givenDate = new Date(dateString);
    return (
        givenDate.getDate() === today.getDate() &&
        givenDate.getMonth() === today.getMonth() &&
        givenDate.getFullYear() === today.getFullYear()
    );
}
function addClickEvent() {
    let noticeInfoList = document.querySelectorAll('.jumpArticle');
    Array.from(noticeInfoList).forEach((e, index) => {
        if (!e.getAttribute('data-event')) {
            e.addEventListener("click", function () {
                articleQuery(e)
            });
            e.setAttribute('data-event', 1);
            // console.log(e)
        }
    })
}
function articleQuery(e) {
    var id = e.getAttribute('data-id')
    var url = e.getAttribute('data-url')
    if (id) {
        ajax('GET', `portalWebsite/article/query?articleId=${id}`, null, function (res) {
            let data = res.data || {};
            jumpArticle(data)
        })
    } else if (url) {
        window.open(url, '_blank')
    } else {
        console.log('未配置跳转类型！', e)
    }

}
function getNowTime() {
    timer = setInterval(() => {
        document.getElementById('newTime').innerHTML = formatTime(new Date())
    }, 999);
};
function queryArticleCarouselChart() {
    ajax('GET', `portalWebsite/homepage/queryArticleCarouselChart`, null, function (res) {
        let { data } = res;
        let mySwiper = document.getElementById('swiper-wrapper-1');
        let htmlStr = ''
        //console.log(data)
        mySwiperList_1 = data || []
        mySwiperList_1.forEach((e, index) => {
            //console.log(e)
            if (index < 6) {
                let domStr = `<div class='swiper-slide jumpArticle' :title='${e.title}' data-id='${e.articleId}'>
                        <img src=${$baseUrl.fileServiceUrl}portalWebsite/files/download?fileId=${e.coverId} />
                        </div>`
                htmlStr += domStr
            }
        })
        mySwiper.innerHTML = htmlStr
        addClickEvent();
        mySwiper_init_1();
        getSwiperTitle(0);
    })
}
//查询专栏轮播
function queryParentList() {
    ajax('GET', `portalWebsite/homepage/queryParentList`, null, function (res) {
        let data = res.data || [];
        let mySwiper = document.getElementById('swiper-wrapper-2');
        let swiperDom = document.getElementById('swiper_2');

        let htmlStr = ''
        if (data.length) {
            data.forEach((e, index) => {
                if (index < 6) {
                    let domStr = `<div class='swiper-slide jumpArticle' data-url='${e.url}'>
                            <img src=${$baseUrl.fileServiceUrl}portalWebsite/files/download?fileId=${e.coverId} />
                            </div>`
                    htmlStr += domStr
                }
            })
            mySwiper.innerHTML = htmlStr
            mySwiper_init_2();
            addClickEvent();
        } else {
            swiperDom.style.display = 'none'
        }
    })
}
function queryCarouselChartType() {
    ajax('GET', `portalWebsite/homepage/queryCarouselChartType`, null, function (res) {
        let data = res.data || [];
        queryAticalList(data);
    })
}

let policeCampCultureListLeft = [];
let policeCampCultureListRight = [];
function queryAticalList(list) {
    var promistList = [];
    let newList = [];
    list.forEach(e => {
        promistList.push(xhrPromise('GET', `portalWebsite/homepage/queryCarouselChart?carouselChartTypeId=${e.carouselChartTypeId}`))
    })
    // 使用Promise.all来同时处理多个请求  
    Promise.all(promistList).then(results => {
        // results是一个数组，包含了所有请求的结果  
        // console.log(results);
        results.forEach((e, i) => {
            if (e.code == 0 && e.data.length) {
                newList.push(list[i])
            }
        })
        // console.log(newList)
        let length = newList.length;
        if (length) {
            let widht = 60 * length;
            let swiperBtnLeft = document.getElementById('swiperBtnLeft')
            let swiper_3 = document.getElementById('swiper_3')
            policeCampCultureListLeft = newList || []
            swiper_3.style.width = `calc(100% - ${widht}px)`
            newList.forEach((e, index) => {
                var newDiv = document.createElement('div');
                newDiv.className = `btn`;
                newDiv.innerHTML = e.carouselChartTypeName
                newDiv.onclick = function () {
                    movePoliceCampCulture(e, 'left')
                };
                swiperBtnLeft.appendChild(newDiv);
            })
            console.log(newList[0])
            movePoliceCampCulture(newList[0], 'left')
            if (policeCampCultureListLeft.length) {
                let lastRut = policeCampCultureListLeft[policeCampCultureListLeft.length - 1]
                queryCarouselChart(lastRut.carouselChartTypeId)
            }
        } else {
            document.getElementById('swiperList').style.display = 'none'
        }

    }).catch(error => {
        // 如果有任何一个请求失败了，就会执行这里的catch  
        console.error('An error occurred:', error);
    });
}
function movePoliceCampCulture(params, flag) {
    let rut = {}
    let length = policeCampCultureListLeft.length
    if (flag == 'left') {
        if (length > 1) {
            rut = policeCampCultureListLeft[length - 1]
            if (rut.carouselChartTypeId == params.carouselChartTypeId) {
                policeCampCultureListRight.unshift(params)
                policeCampCultureListLeft = policeCampCultureListLeft.filter(e => {
                    return e.carouselChartTypeId !== params.carouselChartTypeId
                })
            }
        } else {
            return
        }
    } else {
        if (policeCampCultureListRight.length > 0 && policeCampCultureListRight[0].carouselChartTypeId == params.carouselChartTypeId) {
            policeCampCultureListLeft.push(params)
            policeCampCultureListRight = policeCampCultureListRight.filter(e => {
                return e.carouselChartTypeId !== params.carouselChartTypeId
            })
        } else {
            return
        }

    }
    document.getElementById('swiperBtnLeft').innerHTML = ''
    document.getElementById('swiperBtnRight').innerHTML = ''
    let swiperBtnLeft = document.getElementById('swiperBtnLeft')
    let swiperBtnRight = document.getElementById('swiperBtnRight')
    policeCampCultureListRight.forEach(e => {
        var newDiv = document.createElement('div');
        newDiv.className = `btn`;
        newDiv.innerHTML = e.carouselChartTypeName
        newDiv.onclick = function () {
            movePoliceCampCulture(e, 'right')
        };
        swiperBtnRight.appendChild(newDiv);
    })
    policeCampCultureListLeft.forEach(e => {
        var newDiv = document.createElement('div');
        newDiv.className = `btn`;
        newDiv.innerHTML = e.carouselChartTypeName
        newDiv.onclick = function () {
            movePoliceCampCulture(e, 'left')
        };
        swiperBtnLeft.appendChild(newDiv);
    })
    if (policeCampCultureListLeft.length) {
        let lastRut = policeCampCultureListLeft[policeCampCultureListLeft.length - 1]
        queryCarouselChart(lastRut.carouselChartTypeId)
    }
}
function queryCarouselChart(id) {
    ajax('GET', `portalWebsite/homepage/queryCarouselChart?carouselChartTypeId=${id}`, null, function (res) {
        let data = res.data || [];
        let mySwiper = document.getElementById('swiper-wrapper-3');
        let htmlStr = '';
        data.forEach((e, index) => {
            if (index < 6) {
                let domStr = `<div class='swiper-slide jumpArticle' data-id='${e.articleId}'>
                        <div class='imgBox'><img src=${$baseUrl.fileServiceUrl}portalWebsite/files/download?fileId=${e.filesId} /></div>
                        <div title="${e.title}">${e.title}</div>
                        </div>`
                htmlStr += domStr
            }
        })
        mySwiper.innerHTML = htmlStr
        mySwiper_init_3();
        addClickEvent();
    })
}
